/**
 * 
 * @param {time} time 
 * @returns yyyy-mm-dd H-M-S
 */


const formatTime = (time = new Date().getTime(),format='YYYY-MM-DD H:M:S') => {
  const Y = new Date(time).getFullYear()
  const M = new Date(time).getMonth() + 1
  const D = new Date(time).getDate()
  const h = new Date(time).getHours()
  const m = new Date(time).getMinutes()
  const s = new Date(time).getSeconds()
  
  switch (format) {
    case 'YYYY-MM-DD H:M:S':
      return `${Y}-${M < 10? '0'+M : M}-${D<10?'0'+D:D} ${h<10?'0'+h:h}:${m<10?'0'+m:m}:${s<10?'0'+s:s}`
      case 'YYYY-M-D H:M:S':
      return `${Y}-${M}-${D} ${h<10?'0'+h:h}:${m<10?'0'+m:m}:${s<10?'0'+s:s}`
      case 'YYYY-MM-DD':
      return `${Y}-${M < 10? '0'+M : M}-${D<10?'0'+D:D}`
    default:
      break;
  }
}

export default formatTime